<!doctype html>
<html lang="zh">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <link rel="icon" href="../dist/img/favicon-32x32.png" sizes="32x32" type="image/png">
    <link rel="icon" href="../dist/img/favicon-16x16.png" sizes="16x16" type="image/png">
    <meta name="keywords" content="响应式后台模板,开源免费后台模板,Bootstrap5后台管理系统模板">
    <meta name="description" content="bootstrap-admin基于bootstrap5的免费开源的响应式后台管理模板">
    <meta name="author" content="ajiho">
    <link rel="stylesheet" href="../lib/bootstrap-icons/font/bootstrap-icons.min.css">
    <link rel="stylesheet" href="../lib/bootstrap/dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="../dist/css/bootstrap-admin.min.css">
    <title>bootstrap-admin开源免费响应式后台管理系统模板</title>
</head>
<body class="bg-body-tertiary py-3">
<div class="container-fluid">
    <div class="row row-cols-1 row-cols-sm-1 row-cols-md-1 row-cols-lg-2 g-2">
        <div class="col">
            <div class="card border-0 shadow-sm">
                <div class="card-header bg-body">
                    基础表单验证
                </div>
                <div class="card-body">
                    <form action="#" id="form">
                        <div class="mb-3">
                            <label for="truename" class="form-label">姓名</label>
                            <input type="text" class="form-control" id="truename" name="truename">
                        </div>

                        <div class="mb-3">
                            <label for="username" class="form-label">账号</label>
                            <input type="text" class="form-control" id="username" name="username">
                        </div>
                        <div class="mb-3">
                            <label for="password" class="form-label">密码</label>
                            <input type="text" class="form-control" id="password" name="password">
                            <div id="emailHelp" class="form-text">密码不填写默认为123456</div>

                        </div>

                        <div class="mb-3">
                            <label for="password_confirm" class="form-label">确认密码</label>
                            <input type="text" class="form-control" id="password_confirm"
                                   name="password_confirm">
                        </div>

                        <div class="mb-3">
                            <label for="sexRadio1" class="form-label">性别</label>
                            <div>
                                <div class="form-check form-check-inline">
                                    <input class="form-check-input" type="radio" name="sex" id="sexRadio1"
                                           value="先生"
                                           checked>
                                    <label class="form-check-label" for="sexRadio1">先生</label>
                                </div>
                                <div class="form-check form-check-inline">
                                    <input class="form-check-input" type="radio" name="sex" id="sexRadio2"
                                           value="女士">
                                    <label class="form-check-label" for="sexRadio2">女士</label>
                                </div>
                            </div>
                        </div>
                        <div class="mb-3">
                            <label for="phone" class="form-label">手机</label>
                            <input type="text" class="form-control" id="phone" name="phone">
                        </div>

                        <div class="mb-3">
                            <label for="email" class="form-label">邮箱</label>
                            <input type="text" class="form-control" id="email" name="email">
                        </div>
                        <button type="submit" class="btn btn-primary">添加</button>
                    </form>
                </div>
            </div>
        </div>
        <div class="col">
            <div class="card border-0 shadow-sm">
                <div class="card-header bg-body">
                    水平的label
                </div>
                <div class="card-body">
                    <form action="#" id="form2">
                        <div class="mb-3 row">
                            <label for="username2" class="col-sm-3 col-form-label">用户名</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" id="username2" name="username2">
                            </div>
                        </div>
                        <div class="mb-3 row">
                            <label for="password2" class="col-sm-3 col-form-label">密码</label>
                            <div class="col-sm-9">
                                <input type="password" autocomplete class="form-control" id="password2"
                                       name="password2">
                            </div>
                        </div>
                        <div class="mb-3 row">
                            <label for="confirmPassword2" class="col-sm-3 col-form-label">确认密码</label>
                            <div class="col-sm-9">
                                <input type="password" autocomplete class="form-control" id="confirmPassword2"
                                       name="confirmPassword2">
                            </div>
                        </div>
                        <div class="mb-3 row">
                            <label for="email2" class="col-sm-3 col-form-label">邮箱</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" id="email2" name="email2">
                            </div>
                        </div>
                        <div class="mb-3 row">
                            <label for="gender2Radio1" class="col-sm-3 col-form-label">性别</label>
                            <div class="col-sm-9">
                                <div class="form-check form-check-inline">
                                    <input class="form-check-input" type="radio" name="gender2"
                                           id="gender2Radio1" value="先生">
                                    <label class="form-check-label" for="gender2Radio1">先生</label>
                                </div>
                                <div class="form-check form-check-inline">
                                    <input class="form-check-input" type="radio" name="gender2"
                                           id="gender2Radio2" value="女士">
                                    <label class="form-check-label" for="gender2Radio2">女士</label>
                                </div>
                            </div>
                        </div>

                        <div class="mb-3 row">
                            <label for="age2" class="col-sm-3 col-form-label">年龄</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" id="age2" name="age2">
                            </div>
                        </div>

                        <div class="mb-3 row">
                            <label for="captchaAnswer" id="captchaProblems"
                                   class="col-sm-3 col-form-label">70+115=</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" id="captchaAnswer"
                                       name="captchaAnswer">
                            </div>
                        </div>

                        <div class="mb-3 row">
                            <div class="col-sm-9 offset-sm-3">
                                <input type="checkbox" class="form-check-input" id="agree2" name="agree2">
                                <label class="form-check-label" for="agree2">同意条款协议</label>
                            </div>
                        </div>

                        <div class="mb-3 row">
                            <div class="col-sm-9 offset-sm-3">
                                <button type="submit" class="btn btn-primary">提交</button>
                            </div>
                        </div>

                    </form>
                </div>
            </div>
        </div>
        <div class="col">

            <div class="card border-0 shadow-sm">
                <div class="card-header bg-body">
                    选择验证
                </div>
                <div class="card-body">
                    <form action="#" id="form3">
                        <div class="mb-3 row">
                            <label for="languages-net" class="col-sm-3 col-form-label">编程语言</label>
                            <div class="col-sm-9">
                                <div class="form-check">
                                    <input class="form-check-input" type="checkbox" name="languages[]"
                                           value="net" id="languages-net">
                                    <label class="form-check-label" for="languages-net">
                                        .net
                                    </label>
                                </div>
                                <div class="form-check">
                                    <input class="form-check-input" type="checkbox" name="languages[]"
                                           value="Java" id="languages-Java">
                                    <label class="form-check-label" for="languages-Java">
                                        Java
                                    </label>
                                </div>
                                <div class="form-check">
                                    <input class="form-check-input" type="checkbox" name="languages[]"
                                           value="C/C++" id="languages-C/C++">
                                    <label class="form-check-label" for="languages-C/C++">
                                        C/C++
                                    </label>
                                </div>
                                <div class="form-check">
                                    <input class="form-check-input" type="checkbox" name="languages[]"
                                           value="PHP" id="languages-PHP">
                                    <label class="form-check-label" for="languages-PHP">
                                        PHP
                                    </label>
                                </div>
                                <div class="form-check">
                                    <input class="form-check-input" type="checkbox" name="languages[]"
                                           value="Perl" id="languages-Perl">
                                    <label class="form-check-label" for="languages-Perl">
                                        Perl
                                    </label>
                                </div>
                                <div class="form-check">
                                    <input class="form-check-input" type="checkbox" name="languages[]"
                                           value="Ruby" id="languages-Ruby">
                                    <label class="form-check-label" for="languages-Ruby">
                                        Ruby
                                    </label>
                                </div>
                                <div class="form-check">
                                    <input class="form-check-input" type="checkbox" name="languages[]"
                                           value="Python" id="languages-Python">
                                    <label class="form-check-label" for="languages-Python">
                                        Python
                                    </label>
                                </div>
                                <div class="form-check">
                                    <input class="form-check-input" type="checkbox" name="languages[]"
                                           value="Javascript" id="languages-Javascript">
                                    <label class="form-check-label" for="languages-Javascript">
                                        Javascript
                                    </label>
                                </div>

                            </div>
                        </div>
                        <div class="mb-3 row">
                            <label for="languages-net" class="col-sm-3 col-form-label">编辑器</label>
                            <div class="col-sm-9">
                                <select class="form-select" aria-label="编辑器列表" name="editors[]"
                                        multiple="multiple"
                                        style="height: 200px;">
                                    <option value="atom">Atom</option>
                                    <option value="eclipse">Eclipse</option>
                                    <option value="netbeen">NetBean</option>
                                    <option value="nodepadplusplus">Nodepad++</option>
                                    <option value="phpstorm">PHP Storm</option>
                                    <option value="sublime">Sublime</option>
                                    <option value="webstorm">Web Storm</option>
                                </select>
                            </div>
                        </div>
                        <div class="mb-3 row">
                            <div class="col-sm-9 offset-sm-3">
                                <button type="submit" class="btn btn-primary">提交</button>
                            </div>
                        </div>

                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<!--回到顶部开始-->
<a href="javaScript:" class="bsa-back-to-top"><i class='bi bi-arrow-up-short'></i></a>
<!--回到顶部结束-->



<script src="../lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
<script src="../lib/jquery/dist/jquery.min.js"></script>
<script src="../lib/formvalidation/js/formValidation.js"></script>
<script src="../lib/formvalidation/js/framework/bootstrap.js"></script>
<script src="../lib/formvalidation/js/language/zh_CN.js"></script>
<script src="../dist/js/bootstrap-admin.min.js"></script>
<script src="../dist/js/app.js"></script>
<!--假数据模拟,生产环境中请直接删除该js-->
<script src="../dist/js/bootstrap-admin.mock.js"></script>

<script>
    $(function () {

        //前端表单验证
        $('#form').formValidation({
            fields: {
                truename: {
                    validators: {
                        notEmpty: true,
                    }
                },
                username: {
                    validators: {
                        notEmpty: true,
                        remote: {
                            type: 'post',
                            url: '/check_username.php',
                            data: {
                                type: 'save',
                            },
                            //请求失败的消息
                            message: "系统繁忙,请稍后再试",
                            delay: 1000
                        }
                    }
                },
                password: {},
                password_confirm: {
                    validators: {
                        identical: {
                            field: 'password',
                            message: '和密码不一致'
                        }
                    }
                },
                sex: {
                    validators: {
                        notEmpty: true,
                    }
                },
                phone: {
                    validators: {
                        notEmpty: true,
                        callback: {
                            callback: function (value, validator, $field) {
                                var reg1 = /^\+86-1[3-9]\d{9}$/;
                                var reg2 = /^1[3-9]\d{9}$/;
                                return reg1.test(value) || reg2.test(value);
                            },
                            message: '手机号错误'
                        }
                    },
                },
                email: {
                    validators: {
                        notEmpty: true,
                        emailAddress: {
                            message: "email格式错误"
                        }

                    }
                },
            }
        }).on('success.form.fv', function (e) {
            //阻止表单提交
            e.preventDefault();
            //得到表单对象
            var $form = $(e.target);
            let data = $form.serialize();

            //得到序列化数据
            $.ajax({
                url: "/reg.php",
                method: 'post',
                data: data,
            }).then(function (res) {
                if (res.code === 200) {
                    //注册成功
                } else {
                    //注册失败
                }
            });
        });


        //案例2
        function randomNumber(min, max) {
            return Math.floor(Math.random() * (max - min + 1) + min);
        }

        $("#captchaProblems").html(
            [randomNumber(1, 100), "+", randomNumber(1, 200), "="].join(" ") + "?"
        );

        $("#form2").formValidation({
            //验证字段
            fields: {
                username2: {
                    validators: {
                        notEmpty: true, //也可以像下面那样用
                        stringLength: {
                            min: 6,
                            max: 30,
                            message: "用户名的长度为6-30个字符（这是限制长度的）"
                        },
                        regexp: {
                            regexp: /^[a-zA-Z0-9_\.]+$/,
                            message: "用户名只能由字母、数字、点和下划线组成"
                        }
                    }
                },
                password2: {
                    validators: {
                        notEmpty: {
                            message: "密码不能为空"
                        },
                        different: {
                            field: "username",
                            message: "密码不能和用户名相同"
                        }
                    }
                },
                confirmPassword2: {
                    validators: {
                        notEmpty: true,
                        identical: {
                            field: "password",
                            message: "密码不一致"
                        }
                    }
                },
                email2: {
                    validators: {
                        notEmpty: {
                            message: "电子邮件不能为空"
                        },
                        //验证正确的邮箱
                        emailAddress: true
                    }
                },
                gender2: {
                    validators: {
                        notEmpty: {
                            message: "必须选择一个性别"
                        }
                    }
                },
                age2: {
                    validators: {
                        notEmpty: {
                            message: "必须填写真实年龄"
                        },
                        lessThan: {
                            value: 100,
                            inclusive: true,
                            message: '您是百岁老人'
                        },
                        greaterThan: {
                            value: 18,
                            inclusive: false,
                            message: '未成年人不能进行用户注册'
                        }
                    }
                },
                // 前端验证码
                captchaAnswer: {
                    validators: {
                        callback: {
                            message: "计算错误，请重新验证",
                            callback: function (value, validator, $field) {
                                let items = $("#captchaProblems").html().split(" ");
                                let result = parseInt(items[0]) + parseInt(items[2]);
                                return parseInt(value) === result;
                            }
                        }
                    }
                },
                agree2: {
                    validators: {
                        notEmpty: {
                            message: "您必须同意我们的条款和条件"
                        }
                    }
                }
            }
        }).on('success.form.fv', function (e) {
            //阻止表单提交
            e.preventDefault();
            //得到表单对象
            var $form = $(e.target);
            let data = $form.serialize();

            //得到序列化数据
            $.ajax({
                url: "/reg.php",
                method: 'post',
                data: data,
            }).then(function (res) {
                if (res.code === 200) {
                    //注册成功
                } else {
                    //注册失败
                }
            });
        });


        //案例3
        $('#form3').formValidation({
            fields: {
                'languages[]': {
                    validators: {
                        choice: {
                            min: 2,
                            max: 4,
                            message: '请选择 %s - %s 个你比较擅长的语言'
                        }
                    }
                },
                'editors[]': {
                    validators: {
                        choice: {
                            min: 2,
                            max: 3,
                            message: '请选择 %s - %s 个你比较喜欢的编辑器'
                        }
                    }
                }
            }
        });





    });


</script>
</body>
</html>